<template>
  <div class="login-page">
    <!-- 漂亮的登录界面 -->
    <el-form ref="formRef" :model="formData" :rules="rules" label-width="80px">
      <el-form-item label="账号" prop="account">
        <el-input v-model="formData.account"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formData.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm(formRef)">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import {reactive, ref, onBeforeMount} from "vue";
import {useRouter} from 'vue-router'
import { setToken } from "../utils/cookie";

const Router = useRouter()
const formRef = ref()

const formData = reactive({
  account: '',
  password: ''
})

const rules = reactive({
  account: [
    {required: true, message: '请输入账号'}
  ],
  password: [
    {required: true, message: '请输入密码'}
  ]
})

onBeforeMount(()=>{

})

const submitForm = (formEl) => {
  if (!formRef) return
  formRef.value.validate((valid) => {
    if (valid) {
      const token = 'abc123'
      setToken(token)
      Router.push('/')
    }
  })
}
</script>

<style scoped>

</style>
